package xiaohong.thread;

import java.util.HashMap;
import java.util.Properties;

public class ThreadlocalDemo {

    private static final ThreadLocal<String> threadLocal =
            ThreadLocal.withInitial(() -> "小宏的初始化Thread Local");

    private static final Object lock = new Object();

    public static void main(String[] args) {
        // 创建两个线程来展示 ThreadLocal 的隔离效果
        Thread thread1 = new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + ": " + threadLocal.get());
            threadLocal.set("Thread 1 Value");
            ThreadPoolUtils.execute(() -> {
                System.out.println(Thread.currentThread().getName() + ": " + threadLocal.get());
                threadLocal.set("Thread 2 Value");
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("执行成功");
            });
            System.out.println("执行成功");
        });

        thread1.start();
    }

}
